home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-04-08 | 6.3 KB | 157 lines | [TEXT/CCL2] |
- #|
- palette-class.lisp
-
- Defines the PALETTE class, and its behavior (its attributes, how it
- is created, displayed, closed, and what happens when it is clicked on),
- used in the Mini-Application sample program.
-
- For further info, see files "About Mini-App" and "Instructions".
-
-
- Copyright 1990, 1991 by Ruben Kleiman for Apple Computer, Inc.
-
- Change History.
- 03-11-92 slm *standard-item-height* & *standard-item-width*
- removed as actually local to function layout.
- 03-09-92 slm Updated file header comments.
-
- |#
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; PALETTE window class
- ;;;
- ;;; This class will be used to create instances of palettes which can be
- ;;; used for selecting tools and for dragging objects into the draw windows.
- ;;; Since the DRAW-DIALOG class has methods which are useful for the PALETTE
- ;;; class, we will make PALETTE a subclass of it. We wish palettes to be
- ;;; floating windows. MCL defines a window class called WINDOID which
- ;;; has this property. Therefore, we will use multiple inheritance to get
- ;;; the best of both worlds. We will override or modify the behavior of
- ;;; DRAW-DIALOG methods as needed for PALETTE.
- ;;;
- ;;; my-tools -- a list of tool items to be shown in a palette
- ;;; my-draw-items -- a list of draw items which can be dragged
- ;;; from a palette onto a window
- ;;;
- (defclass palette (draw-dialog)
- ((my-tools :initarg :tools)
- (my-draw-items :initarg :draw-items))
- (:documentation "The class of palettes used in our application"))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; window-close
- ;;;
- ;;; This will ensure that when the close box is clicked,
- ;;; the palette will merely hide and that the Palette
- ;;; menu item is enabled.
- ;;;
- (defmethod window-close ((palette palette))
- (menu-item-enable *palette-menu-item*)
- (window-hide palette))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; view-click-event-handler
- ;;;
- ;;; This gets called by MCL when the mouse goes down in the palette.
- ;;; We want to make sure that the palette always dispatches the
- ;;; mouse-down event because tools need it. The rest of the behavior is the
- ;;; same as in the draw-dialog windows, except that palettes are always
- ;;; in author mode
- ;;;
- (defmethod view-click-event-handler ((palette palette) where)
- (let ((item (find-view-containing-point palette where)))
- (mouse-down item where) ; dispatch the mouse-down event
- (call-next-method))) ; proceed with the usual behavior
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; layout
- ;;;
- ;;; This gets called when a palette must be laid out.
- ;;; It provides a reasonable palette layout, based on the tools and
- ;;; draw-items provided for it.
- ;;;
- (defmethod layout ((palette palette))
- (let* ((tools (slot-value palette 'my-tools))
- (draw-items (slot-value palette 'my-draw-items))
- (v 10) ; starting vertical
- (default-item-width 16)
- (default-item-height 16)
- (max-item-width 0)
- size)
- ;; Local function layout-item will be used twice below:
- (labels ((layout-item (item start-h)
- (unless (view-size item)
- (set-view-size item default-item-width default-item-height))
- (setf size (view-size item))
- (setf max-item-width (max (point-h size) max-item-width))
- (set-view-position item start-h v)
- (setf v (+ v (point-v size) 4))))
- ;; Layout the tools:
- (dolist (tool tools)
- (layout-item tool 16))
- ;; Provide extra separation between tools and draw-items:
- (setq v (+ v 8))
- ;; Layout the draw-items:
- (dolist (draw-item draw-items)
- (layout-item draw-item 24)))
- ;; Now add the tools and draw-items into the palette:
- (apply #'add-items (cons palette tools))
- (apply #'add-items (cons palette draw-items))
- (set-view-size palette (+ max-item-width 32) v)))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; add-items
- ;;;
- ;;; This is called to put draw-items into a window
- ;;; It creates the rectangle used to drag and resize it
- ;;; under direct manipulation
- ;;;
- (defmethod add-items ((window draw-dialog) &rest items)
- (dolist (item items)
- ;; Set draw-item's rectangle for tracking
- (setf (slot-value item 'rectangle)
- (make-record :rect
- :topleft (view-position item)
- :bottomright (add-points (view-position item)
- (view-size item)))))
- (apply #'add-subviews (cons window items)))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; show-palette
- ;;;
- ;;; Show palette, if it exists; else create one and show it.
- ;;; Remember to update the Palette menu item hiliting.
- ;;; We assume that the global variables *available-tools* and
- ;;; *available-draw-items* are lists of already defined tools
- ;;; and draw items, respectively. The tools and draw items
- ;;; are defined below, in the DRAW ITEMS section
- ;;;
- (defun show-palette ()
- (let ((palette (car (windows :class 'palette))))
- (if palette
- (window-show palette)
- (setq palette (create-palette)))
- (menu-item-enable *palette-menu-item*)))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; create-palette
- ;;;
- ;;; Creates, does the layout for and returns a brand new palette
- ;;;
- (defun create-palette (&key (tools *available-tools*)
- (items *available-draw-items*))
- (let ((palette (make-instance 'palette
- :window-title "Tools"
- :window-type :tool
- :window-show nil
- :view-position #@(310 40)
- :view-size #@(100 300)
- :tools tools
- :draw-items items)))
- (layout palette)
- (window-show palette)
- palette))
-
- ;end of file palette-class.lisp
- ;------------------------------------------------
-